﻿@{
    ViewBag.Title = "TransitionContractIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
@using LeSoft.Application.Code;
<script>
    var _organizeid = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId", _state = "All", _pstructId = "", _Type = 5;
    $(function () {
        InitialPage();
        GetTree1();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 137.5);
            }, 200);
            e.stopPropagation();
        });

        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
        $("#time_horizon").ComboBox({
            data: [{ "key": 2, "value": "上周" }, { "key": 1, "value": "本周" }, { "key": 4, "value": "上月" }, { "key": 3, "value": "本月" }, { "key": 5, "value": "本年" }],
            id: "key",
            text: "value",
            description: "=选择=",
            click: function (item) {
                var value = item.attr('data-value');
                switch (value) {
                    case "1"://本周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        break;
                    case "2"://上周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        break;
                    case "3"://本月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "4"://上月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(-1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "5"://本年
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.DayOfYear + 1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(12 - DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    default:
                        break;
                }
                $("#SelectedStartTime").html($("#StartTime").val());
                $("#SelectedEndTime").html($("#EndTime").val());
                SearchEvent();
            }
        });
        $("#time_horizon").ComboBoxSetValue(3);
    }

    function GetTree1() {
        var item = {
            url: "../../QualificationManage/Contract/GetTreeList?Type=" + _Type,
            onnodeclick: function (item) {
                if (item.id != _state) {
                    _state = item.id;
                    SearchEvent();
                }
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
    }
    function GetGrid() {
        var queryJson = {
            State: _state,
            BeginDate: $("#StartTime").val(),
            EndDate: $("#EndTime").val() + " 23:59:59",
            PstructId: _pstructId,
            OrganizeId: _organizeid,
            Type: _Type
        };
        var $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            url: "../../QualificationManage/Contract/GetPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 137.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "id", hidden: true },
                { label: "主键", name: "contractid", hidden: true },
                { label: "主键", name: "liveinuserid", hidden: true },
                { label: "承租人", name: "customername", index: "customername", width: 150, align: "left", hidden: true },
                { label: "承租人", name: "membername", index: "membername", width: 150, align: "center" },
                { label: "申请单号", name: "code", index: "code", width: 180, align: "center" },
                {
                    label: "申请日期", name: "date", index: "date", width: 120, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
                    }
                },
                {
                    label: "业务种类", name: "type", index: "type", width: 90, align: "center",
                    formatter: function (cellvalue, options, rowObject) {

                        switch (cellvalue) {
                            case 5: return "过渡合同申请"; break;
                            default: return ""; break;
                        }
                    }
                },
                {
                    label: "审批状态", name: "state", index: "state", width: 70, align: "center",
                    formatter: function (cellvalue, options, rowObject) {

                        switch (cellvalue) {
                            case 0: return "未提交"; break;
                            case 1: return "审批中"; break;
                            case 2: return "审批通过"; break;
                            case 3: return "审批未通过"; break;
                            default: return ""; break;
                        }
                    }
                },
                { label: "合同编号", name: "ccode", index: "ccode", width: 180, align: "center" },
                { label: "租赁房产", name: "roomallname", index: "roomallname", width: 240, align: "left" },

                {
                    label: "起始日期", name: "begindate", index: "begindate", width: 120, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd');
                    }
                },
                {
                    label: "终止日期", name: "enddate", index: "enddate", width: 120, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd');
                    }
                },
                { label: "备注", name: "description", index: "description", width: 100, align: "left" }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100, 500, 1000],
            pager: "#gridPager",
            sortname: 'date desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                var State = $gridTable.jqGridRowValue("state");
                var Type = $gridTable.jqGridRowValue("type");
                if (State.indexOf("审批未通过", State) == 0 && Type.indexOf("合同续租", Type) == 0) {
                    $(".GDHT").removeAttr("disabled");
                }
                else {
                    $(".GDHT").attr("disabled", "disabled");
                }
            },
        });

        //查询点击事件
        $("#btn_Search").click(function () {
            SearchEvent();
            $('#btn_Reset').trigger("click");
            $(".ui-filter-text").trigger("click");
        });
        $("#btn_Reset").click(function () {
            $("#Code").val("");
            $("#Name").val("");
            $("#IDCard").val("");
            $("#PStruct").val("");
        })
    }

    function SearchEvent() {
        var queryJson = {
            State: _state,
            BeginDate: $("#StartTime").val(),
            EndDate: $("#EndTime").val() + " 23:59:59",
            Name: $("#Name").val(),
            Code: $("#Code").val(),
            IDCard: $("#IDCard").val(),
            PStruct: $("#PStruct").val(),
            PstructId: _pstructId,
            OrganizeId: _organizeid,
            Type: _Type
        };
        $("#gridTable").jqGrid('setGridParam', {
            url: "../../QualificationManage/Contract/GetPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            page: 1
        }).trigger('reloadGrid');
    }
    //审批
    function btn_Audit() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        var ContractId = $("#gridTable").jqGridRowValue("contractid");
        var type = $("#gridTable").jqGridRowValue("type");
        var LiveInUserId = $("#gridTable").jqGridRowValue("liveinuserid");
        if (checkedRow(keyValue)) {
            switch (type) {
                case "过渡合同申请": type = 5; break;
                default:
                    dialogMsg("数据错误，请选择其他数据！", 0);
                    return false;
                    break;
            }
            var url = '/QualificationManage/Contract/TransitionContractForm?keyValue=' + keyValue + "&ContractId=" + ContractId + "&Type=" + type + "&MemberId=" + LiveInUserId;
            dialogOpen({
                id: "Detail",
                title: '过渡合同申请单',
                url: url,
                width: "1100px",
                height: "770px",
                btn: ["关闭"],
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }

    //添加
    function btn_add() {
        dialogOpen({
            id: "TransitionForm",
            title: '过渡合同申请单',
            url: '/QualificationManage/Contract/TransitionForm',
            width: "1300px",
            height: "770px",
            btn: ["关闭"],
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        }); 
    }

</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height: 98%; overflow-y: auto; ">
            <div id="itemTree1"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>签约日期</td>
                            <td style="padding-left: 10px;">
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">签约日期：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" readonly type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" readonly type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">姓名：</td>
                                                <td class="formValue">
                                                    <input id="Name" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">申请单号：</td>
                                                <td class="formValue">
                                                    <input id="Code" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">身份证号：</td>
                                                <td class="formValue">
                                                    <input id="IDCard" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">租赁房产：</td>
                                                <td class="formValue">
                                                    <input id="PStruct" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr>
                                        </table>
                                        <div class="ui-filter-list-bottom">
                                            <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                            <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="time_horizon" type="selectTree" class="ui-select" style="width: 60px;"></div>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-audit" class="btn btn-default" onclick="btn_Audit()"><i class="fa fa-wrench"></i>&nbsp;审批</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>
